package testcase.login;

import basic.BasicCase;
import org.junit.Assert;
import org.testng.annotations.Test;

import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by 13714526025 on 2018/9/19.
 * Description：退出账号
 */
public class LoginOut extends BasicCase {
    String oppoPwd = "youyou961115";

    //    public static void main(String[] args) {
//        String t="退出 OPPO 帐号 \"137******25\" 将影响部分软件的使用，请输入密码确认退出。";
//        String p = "\"([^\"]*)\"" ;
//        Pattern P= Pattern.compile(p);
//        Matcher matcher1=P.matcher(t);
//        if(matcher1.find())
//        {
//            System.out.println(matcher1.group(1).replaceAll(p, "$1"));
//        }
//    }
    @Test
    public void testName() {
        finder.waitforWebElement("com.oppo.ohome:id/iv_setting");
        //跳转oppo会员账号页面
        finder.findElementById("com.oppo.ohome:id/tv_title").click();

        //在手机上删除数据

        try {
            if (finder.waitforWebElement("com.oppo.usercenter:id/tv_user_fullname")) {
                finder.scrollList(2);
                finder.findElementByText("退出帐号").click();
                finder.findElementById("com.oppo.usercenter:id/cloud_delete").click();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        try{
            if(finder.waitforWebElement("com.oppo.usercenter:id/cloud_delete")){
                finder.findElementByText("取消").click();
                finder.scrollList(2);
                finder.findElementByText("退出帐号").click();
                finder.findElementById("com.oppo.usercenter:id/cloud_delete").click();
            }

        }catch(Exception e1){
            e1.printStackTrace();
        }
        try{
            if(finder.waitforWebElement("com.oppo.usercenter:id/edit_input_content")){
                finder.findElementByText("取消").click();
                finder.findElementByText("取消").click();
                finder.waitforWebElement("com.oppo.usercenter:id/action_bar_title");
                finder.scrollList(2);
                finder.findElementByText("退出帐号").click();
                finder.findElementById("com.oppo.usercenter:id/cloud_delete").click();
            }
        }catch(Exception e2){
            e2.printStackTrace();
        }
        String titleStr = finder.findElementById("com.oppo.usercenter:id/alertTitle").getText();
        //正则表达式分割手机号码
        String t = titleStr;
        String p = "\"([^\"]*)\"";
        Pattern P = Pattern.compile(p);
        Matcher matcher1 = P.matcher(t);
        if (matcher1.find()) {
            System.out.println(matcher1.group(1).replaceAll(p, "$1"));
        }
        try {
            if ((matcher1.group(1).replaceAll(p, "$1")).equals("137******25")) {
                finder.findElementById("com.oppo.usercenter:id/edit_input_content").sendKeys(oppoPwd);
                finder.findElementById("android:id/button1").click();
            }

        } catch (Exception e) {
            Logger log = Logger.getLogger("phone Exception log");
            log.setLevel(Level.INFO);
        }
        finder.waitforWebElement("com.oppo.ohome:id/iv_setting");
        //断言是否退出
        Assert.assertTrue(finder.findElementById("com.oppo.ohome:id/tv_title").getText().equals("点击登录"));

    }
}
